﻿using System;
using System.Linq;
using System.Web.Services;
using System.Web.UI;
using App_Code.Clases;
using App_Code.Utilidades;
using SubSonic.Repository;

public partial class Mantenimiento_Roles_VerRoles : Page
{
    static SimpleRepository repository = new SimpleRepository("Electro",SimpleRepositoryOptions.None);
    protected void Page_Load(object sender, EventArgs e)
    {
        Validaciones.ValidarSession();
        if(!Page.IsPostBack)
        {
            var roles = from r in repository.All<Rol>()
                        select r;
            GridRoles.DataSource = roles;
            GridRoles.DataBind();
        }
    }

    [WebMethod]
    public static string EliminarRol(int idRol)
    {
        try
        {
            var rol = repository.Single<Rol>(idRol);
            var codigo = rol.Nombre;
            repository.Delete<Rol>(rol.Id);
            return "El rol " + codigo + " ha sido eliminado correctamente";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
}
